package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetMealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/setmeal_mobile")
public class SetmealController {

    @Reference
    private SetMealService setmealSerivce;

    @RequestMapping("/getSetmeal")
    public Result getSetmeal(){
        try{
            List<Setmeal> setmealList = setmealSerivce.findAll();
//            System.out.println(setmealList);
            return new Result(true,null,setmealList);
        }catch(Exception e){
            e.printStackTrace();
            return  new Result(false,null);
        }
    }


    @RequestMapping("/findById")
    public Result findById(Integer id){
        try{
            Setmeal  setmeal  = setmealSerivce.findById(id);
            return new Result(true,MessageConstant.GET_SETMEAL_LIST_SUCCESS,setmeal);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }

    @RequestMapping("/findSetmealById")
    public Result findSetmealById(Integer id){
        try{
            Setmeal  setmeal  = setmealSerivce.findSetmealById(id);
            return new Result(true,MessageConstant.GET_SETMEAL_LIST_SUCCESS,setmeal);
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false, "服务器正忙，请稍后重试");
        }
    }
}
